import Vue from 'vue'
import Router from 'vue-router'

import Login from '../components/Login'
import Home from '../components/Home'
import Registe from '../components/Registe'
import AddStu from '../components/AddStu'
import ShowStu from '../components/ShowStu'
import Daliy from '../components/Daliy'

import Interview from '../system/Interview'
import DashBoard from '../system/DashBoard'
import Msbd from '../system/Msbd'
import Msbd2 from '../system/Msbd2'
import Users from '../system/Users'
import Abc from '../system/Abc'

import ss from '../utils/ss'


Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login
    },
    {
      path: '/registe',
      name: 'Registe',
      component: Registe
    },
    {
      path: '/home',
      component: Home,
      children: [
        {
          path: '',
          component: ShowStu,
        },
        {
          path: 'add',
          component: AddStu,
          name: 'AddStu',
          props: (route) => ({ stuData: route.params })
        },
        {
          path: '/interview',
          component: Interview,
          children: [
            { path: '', component: DashBoard },
            { path: 'dashBoard', component: DashBoard },
            { path: 'msbd', component: Msbd, name: 'msbd', alias: '/ms/msbd' },
            { path: 'msbd2', component: Msbd2, name: 'msbd2', alias: '/ms/msbd2' },
            { path: 'users', component: Users, alias: '/settings/users' },
          ]
        }
      ]
    },
    {
      path: '/daliy',
      component: Home,
      children: [
        {
          path: '',
          component: Daliy
        }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  const arr = ['/', '/registe']
  const userinfo = ss.get()
  if (arr.includes(to.path)) {
    next()
  } else {
    if (userinfo.token) {
      next()
    } else {
      next('/')
    }
  }
})

export default router
